package com.bing.jh.service.impl;

import cn.hutool.core.text.CharSequenceUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bing.bingPro.util.ProvinceUtil;
import com.bing.jh.domain.DzWzUserGroupStat;
import com.bing.jh.entity.dto.TZwArchivesDto;
import com.bing.jh.entity.vo.DzWzUserGroupStatVO;
import com.bing.jh.enums.DzWzUserGroupStatEnums;
import com.bing.jh.service.DzWzUserGroupStatService;
import com.bing.jh.mapper.DzWzUserGroupStatMapper;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author ck
* @description 针对表【dz_wz_user_group_stat】的数据库操作Service实现
* @createDate 2024-06-09 15:00:48
*/
@Service
public class DzWzUserGroupStatServiceImpl extends ServiceImpl<DzWzUserGroupStatMapper, DzWzUserGroupStat>
    implements DzWzUserGroupStatService{

    @Override
    public List<DzWzUserGroupStatVO> list(TZwArchivesDto tZwArchives) {
        tZwArchives.setMonth(tZwArchives.getMonth().replace("-",""));
        tZwArchives.setProvinceCode(ProvinceUtil.getProvinceCode(tZwArchives.getProvinceCode()));
        List<DzWzUserGroupStatVO> list = baseMapper.list(tZwArchives);
        list.forEach(dzWzUserGroupStatVO -> {
            Integer groupStatCode = Integer.valueOf(dzWzUserGroupStatVO.getGroupStat());
            DzWzUserGroupStatEnums groupStatEnum = DzWzUserGroupStatEnums.fromCode(groupStatCode);
            if (groupStatEnum != null) {
                dzWzUserGroupStatVO.setGroupStat(groupStatEnum.getType());
            }
        });
         if (CharSequenceUtil.isEmpty(tZwArchives.getCounty())) {
            DzWzUserGroupStatVO dzWzUserGroupStatVO = baseMapper.queryCn(tZwArchives);
            Integer groupStatCode = Integer.valueOf(dzWzUserGroupStatVO.getGroupStat());
            DzWzUserGroupStatEnums groupStatEnum = DzWzUserGroupStatEnums.fromCode(groupStatCode);
            if (groupStatEnum != null) {
                dzWzUserGroupStatVO.setGroupStat(groupStatEnum.getType());
            }
            list.add(0, dzWzUserGroupStatVO);
        }
        return list;
    }

    @Override
    public List<String> dateList() {
        return baseMapper.dateList();
    }

    @Override
    public List<DzWzUserGroupStatVO> queryAll(TZwArchivesDto tZwArchives) {
        tZwArchives.setMonth(tZwArchives.getMonth().replace("-",""));
        tZwArchives.setProvinceCode(ProvinceUtil.getProvinceCode(tZwArchives.getProvinceCode()));
        List<DzWzUserGroupStatVO> list = baseMapper.list(tZwArchives);
        list.forEach(dzWzUserGroupStatVO -> {
            Integer groupStatCode = Integer.valueOf(dzWzUserGroupStatVO.getGroupStat());
            DzWzUserGroupStatEnums groupStatEnum = DzWzUserGroupStatEnums.fromCode(groupStatCode);
            if (groupStatEnum != null) {
                dzWzUserGroupStatVO.setGroupStat(groupStatEnum.getType());
            }
        });
        List<DzWzUserGroupStatVO> dzWzUserGroupStatVOList = baseMapper.queryCity(tZwArchives);
        list.addAll(dzWzUserGroupStatVOList);
        if (CharSequenceUtil.isEmpty(tZwArchives.getCounty())) {
            DzWzUserGroupStatVO dzWzUserGroupStatVO = baseMapper.queryCn(tZwArchives);
            Integer groupStatCode = Integer.valueOf(dzWzUserGroupStatVO.getGroupStat());
            DzWzUserGroupStatEnums groupStatEnum = DzWzUserGroupStatEnums.fromCode(groupStatCode);
            if (groupStatEnum != null) {
                dzWzUserGroupStatVO.setGroupStat(groupStatEnum.getType());
            }
            list.add(0, dzWzUserGroupStatVO);
        }
        return list;
    }
}




